﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Players = Userslib.localhost.Users;
using Villages = Userslib.localhost.Village;
namespace Userslib
{
    /*
     * This class is used to look up a player in the database.
     * It contacts the webservice for the necessary information and if the player exists, populates its fields.
     */
    public class Player
    {
        private static localhost.GetData ws = new localhost.GetData();

        private int pop;
        private int pid;
        private String name;
        private String tribe;
        private List<localhost.Village> villageList = new List<localhost.Village>();
        
        public int Population { get {return this.pop; } }
        public int PID { get { return this.pid; } }
        public String Name { get { return this.name; } }
        public String Tribe { get { return this.tribe; } }
        public List<localhost.Village> VillageList { get { return this.villageList; } }

        public bool isValid = false;
        
        public Player(String Name)
        {
            
            var details = from Players player in ws.Get_Member(Name) select new { Name = player.Name, PID = player.PID, Pop = player.Pop,Tribe = Races.getRace(player.Tribe) };
            if (details.Count() == 1)
            {
                isValid = true;
                this.name = details.FirstOrDefault().Name;
                this.pop = details.FirstOrDefault().Pop;
                this.pid = details.FirstOrDefault().PID;
                this.tribe = details.FirstOrDefault().Tribe;
                var villages = from localhost.Village village in ws.Get_Villages(Name) select village;
                villageList.AddRange(villages);
            }
        }
    }


}
